﻿using Dapper;
using HR.Filters;
using HR.IService;
using HR.Models;
using Microsoft.AspNetCore.Mvc;
using System.Data.SqlClient;

namespace Hr.Controllers
{
    public class Major_changeController : Controller
    {
        private readonly IMajor_changeService changeService;

        public Major_changeController(IMajor_changeService changeService)
        {
            this.changeService = changeService;
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        public IActionResult Index()
        {
            return View();
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        public IActionResult changeselect()
        {
            return View();
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        public IActionResult selectpage()
        {
            return View();
        }
        SqlConnection conn = new SqlConnection("Data Source=YUANZAIZAI-PC;Initial Catalog=HR_DB;Persist Security Info=True;User ID=sa;Password=root;TrustServerCertificate=true");
        public IActionResult Third1()
        {
            //获取一级数据
            string sql = @"select first_kind_id as id,first_kind_name as name
            from config_file_first_kind";
            List<yiji> list = conn.Query<yiji>(sql).ToList();
            foreach (yiji item in list)
            {
                //获取2级数据
                string sql2 = $@"select second_kind_id as id,second_kind_name as name
                from dbo.config_file_second_kind
                where first_kind_id='{item.id}'";
                item.children = conn.Query<erji>(sql2).ToList();
                foreach (erji item2 in item.children)
                {
                    //获取3级数据
                    string sql3 = $@"select third_kind_id as id,third_kind_name as name
                    from config_file_third_kind
                    where second_kind_id='{item2.id}'";
                    item2.children = conn.Query<sanji>(sql3).ToList();
                }
            }
            return Json(list);
        }

        public IActionResult Third2()
        {
            //获取一级数据
            string sql = @"select major_kind_id as id,major_kind_name as name
            from config_major_kind";
            List<yiji> list = conn.Query<yiji>(sql).ToList();
            foreach (yiji item in list)
            {
                //获取2级数据
                string sql2 = $@"select major_id as id,major_name as name
                from config_major
                where major_kind_id={item.id}";
                item.children = conn.Query<erji>(sql2).ToList();
            }
            return Json(list);
        }
        [HttpGet]
        public async Task<IActionResult> Select()
        {
            List<salary_standard> configs = await changeService.Select();
            return Json(configs);
        }

        public async Task<IActionResult> FenYeSelect_dji([FromBody] major_change_CX change_CX)
        {
            FenYe<human_file> fenYe = await changeService.changeFenYe(change_CX);
            return Json(fenYe);
        }
        public async Task<IActionResult> FenYeSelect(int pageSize, int currentPage)
        {
            FenYe<human_file> fenYe = await changeService.changeFenYe1(pageSize, currentPage);
            return Json(fenYe);
        }
        public async Task<IActionResult> FenYeSelect2(int pageSize, int currentPage)
        {
            FenYe<major_change> fenYe = await changeService.changeFenYe2(pageSize, currentPage);
            return Json(fenYe);
        }

        public async Task<IActionResult> Update([FromBody] major_change change)
        {
            return Content((await changeService.major_changeUpdate(change)).ToString());
        }

        public async Task<IActionResult> Add([FromBody] major_change change)
        {
            return Content((await changeService.major_changeAdd(change)).ToString());
        }
        [HttpPost]
        public async Task<IActionResult> Select([FromBody] major_change_CX change_CX)
        {
            List< major_change > list=await changeService.major_changeSelect(change_CX);
            return  Json((list));
        }
        [HttpGet]
        public async Task<IActionResult> Select1()
        {
            List<major_change> list = await changeService.major_changeSelect1();
            return Json((list));
        }

        public IActionResult human_fileUpdate([FromBody] human_file file)
        {
            return Content((changeService.human_fileUpdate(file)).ToString());
        }

        //public IActionResult human_fileselect(string human_id)
        //{
        //    List<human_file> list = changeService.human_fileselect(human_id);
        //    return Json(list);
        //}
    }
}
